function G() {
    this.index = 0
}

G.prototype.create = function (o) {
    ++this.index;
    let o1 = {};
    for (var key in o) {
        if (typeof (o[key]) != "object") {
            let k1 = o[key].toLowerCase();
            switch (k1) {
                case "key":
                    o1[key] = "key" + this.index;
                    break;
                case "date":
                    o1[key] = new Date().toDateString();
                    break;
                case "datetime":
                    o1[key] = new Date().toString();
                    break;
                case "bool":
                    o1[key] = Math.random() < 0.5 ? true : false;
                    break;
                default:
                    o1[key] = o[key].replace(/\{0\}/g, this.index);
                    break;
            }
        }
        else if (o[key] === null) {
            o1[key] = 'key value is null,please checked.';
        }
        else if (o[key].length) {
            if (o[key][0] === "all") {
                o1[key] = []
                for (let pos = 1; pos < o[key].length; pos++) {
                    o1[key].push(this.create(o[key][pos]))
                }
            }
            else {
                o1[key] = o[key][Math.floor(Math.random() * o[key].length)];
            }
        }
        else {
            o1[key] = this.create(o[key]);
        }
    }
    return o1
};

const generateData = new G();

export default generateData